package com.ironman.analyze.core.rest;

import com.ironman.analyze.core.compute.entity.Training;
import com.ironman.analyze.core.service.TrainingService;
import com.ironman.common.SailingParamWrapper;
import com.ironman.common.params.WindParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/sailboat-training")
@RequiredArgsConstructor
public class SailboatTrainingController {

    final TrainingService trainingService;

    @PostMapping("wind")
    public List<String> wind(@RequestParam(value = "startTime") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date startTime,
                             @RequestParam(value = "endTime") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date endTime,
                             @RequestBody WindParam windParam) {
        String tenantCode = "1188";
        return trainingService.wind(tenantCode, startTime, endTime, windParam);
    }

    @PostMapping(value = {"track", "report"})
    public Training build(@RequestParam("levelId") String levelId,
                          @RequestParam("mHmId") String mHmId,
                          @RequestParam("trainingDay") @DateTimeFormat(pattern = "yyyy-MM-dd") Date trainingDay,
                          @RequestParam(value = "startTime") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date startTime,
                          @RequestParam(value = "endTime") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date endTime,
                          @RequestParam(value = "report", required = false, defaultValue = "false") boolean report,
                          @RequestBody SailingParamWrapper sailingParam) {
        String tenantCode = "1188";
        return trainingService.build(tenantCode, levelId, mHmId, trainingDay, startTime, endTime, report, sailingParam);
    }
}
